package org.gary.admin.service.impl;

import java.util.Date;

import javax.annotation.Resource;

import org.gary.admin.dao.LoggerDao;
import org.gary.admin.model.Logger;
import org.gary.admin.service.LoggerService;
import org.gary.core.factories.impl.BasicServiceFactoryImpl;
import org.springframework.stereotype.Component;

/**
 * 日志service类
 * @author lengreen
 *
 */
@Component("loggerService")
public class LoggerServiceImpl extends BasicServiceFactoryImpl<Logger>
		implements LoggerService {
	private LoggerDao loggerDao;
	
	/**
	 * 添加日志方法
	 * @param target 日志添加的目标，如可以是某个类的某个方法比如当Save Category时候可以是Category Save event
	 * @param doWhat 对这个Category表做了什么操作，可以是增删改查等等
	 */
	public void makeLog(String target, String doWhat) {
		Logger log = new Logger(target, doWhat);
		try {
			getBasicDaoFactory().save(log);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 添加日志方法
	 * @param target 日志添加的目标，如可以是某个类的某个方法比如当Save Category时候可以是Category Save event
	 * @param doWhat 对这个Category表做了什么操作，可以是增删改查等等
	 * @param date 自定义添加日志时间
	 */
	public void makeLog(String target, String doWhat, Date date) {
		Logger log = new Logger(target, doWhat, date);
		getBasicDaoFactory().save(log);
	}

	@Override
	public void delete(String from, String to) {
		loggerDao.delete(from, to);
	}

	@Resource
	public void setLoggerDao(LoggerDao loggerDao) {
		this.loggerDao = loggerDao;
	}

	public LoggerDao getLoggerDao() {
		return loggerDao;
	}
}
